package cn.sw.file.controller;

import cn.sw.common.database.architecture.emun.BaseServiceOf;
import cn.sw.common.database.domain.dto.form.AttachmentFormDto;
import cn.sw.common.database.domain.dto.query.AttachmentQueryDto;
import cn.sw.common.database.domain.entity.Attachment;
import cn.sw.common.database.domain.vo.vo.AttachmentVo;
import cn.sw.common.entity.R;
import cn.sw.file.service.AttachmentService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import cn.sw.common.database.architecture.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 附件表 前端控制器
 *
 * @author 张众森 (个人博客:https://)
 * @date 2025-05-23
 * @tags 做一个优秀的全栈架构
 */
@Api(tags = "Attachment控制器")
@RestController
@RequestMapping("/attachment")
@BaseServiceOf(Attachment.class)
public class AttachmentController extends BaseController<Attachment, AttachmentFormDto, AttachmentQueryDto, AttachmentVo> {

    @Resource
    private AttachmentService attachmentService;

    @PostMapping("/uploadFile")
    public R<String> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        return attachmentService.uploadFile(file);
    }

    @GetMapping("/downloadFile/{id}")
    public void downloadFile(@PathVariable("id") String id, HttpServletResponse response) throws IOException {
         attachmentService.downloadFile(id, response);
    }

}
